package com.dc.bobaoge.project.base.core.mq;

import com.dc.bobaoge.common.constant.ConstantMq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * MessageSyncConfig
 *
 * @author chenxueli
 * @date 2023-09-11 08:20:00
 */
@Slf4j
@SpringBootConfiguration
public class MessageSyncConfig {

    /**
     * 声明队列
     *
     * @return 队列
     */
    @Bean
    public Queue messageSyncMq() {
        return new Queue(ConstantMq.MESSAGE_SYNC_QUEUE);
    }

    /**
     * 声明exchange
     *
     * @return exchange
     */
    @Bean
    public FanoutExchange messageSyncMqExchange() {
        return new FanoutExchange(ConstantMq.MESSAGE_SYNC_EXCHANGE);
    }

    /**
     * 声明Binding,exchange与queue的绑定关系
     *
     * @return Binding
     */
    @Bean
    public Binding bindMessageSync() {
        return BindingBuilder.bind(messageSyncMq()).to(messageSyncMqExchange());
    }

}
